package com.example.kotlin.activity

import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.graphics.BitmapFactory
import android.os.Build
import android.os.Bundle
import androidx.core.app.NotificationCompat
import com.example.kotlin.R
import kotlinx.android.synthetic.main.activity_notification.sendNotification

class NotificationActivity : BaseActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_notification)

        val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

        if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){

//            val channel=NotificationChannel("normal","Normal",NotificationManager.IMPORTANCE_DEFAULT)
//            manager.createNotificationChannel(channel)

            val channel2=NotificationChannel("important","Important",NotificationManager.IMPORTANCE_HIGH)
            manager.createNotificationChannel(channel2)
        }

//        sendNotification.setOnClickListener {
//            val intent=Intent(this,RuntimeActivity::class.java)
//            val pi=PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE)
//            val notification = NotificationCompat.Builder(this, "normal")
//                .setContentTitle("这是通知标题")
//                .setContentText("这是通知内容")
//                .setSmallIcon(R.mipmap.smallheader)
//                .setLargeIcon(BitmapFactory.decodeResource(resources,R.mipmap.largeheader))
//                .setContentIntent(pi)
//                .setAutoCancel(true)
//                .build()
//            manager.notify(1,notification)
//        }
        sendNotification.setOnClickListener {
            val intent=Intent(this,RuntimeActivity::class.java)
            val pi=PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE)
            val notification = NotificationCompat.Builder(this, "important")
                .setContentTitle("这是通知标题")
                .setContentText("这是通知内容")
                .setSmallIcon(R.mipmap.smallheader)
                .setLargeIcon(BitmapFactory.decodeResource(resources,R.mipmap.largeheader))
                .setContentIntent(pi)
                .setAutoCancel(true)
                .build()
            manager.notify(1,notification)
        }
    }
}